﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Oracle.DataAccess.Client;

namespace ERP.Source.DBBridge
{
    public static class Database
    {
        private static string dBName;
        private static OracleConnection conn;

        public static string DBName
        {
            set
            {
                dBName = value;
            }
            get
            {
                return dBName;
            }
        }

        public static OracleConnection Conn
        {
            set
            {
                conn = value;
            }
            get
            {
                return conn;
            }
        }

        public static bool Connect()
        {
            dBName = @"Data Source=orcl;User Id=TEST;Password=Oracle123;";
            bool isConnected = false;

            try
            {
                conn = new OracleConnection(dBName);
                conn.Open();
                isConnected = true;
            }

            catch(Exception ex)
            {
                isConnected = false;
            }

            return isConnected;
        }

        public static bool Disconnect()
        {
            bool isDisconnect = false;

            if (conn.State != ConnectionState.Closed)
            {
                conn.Close();
                conn.Dispose();
                isDisconnect = true;
            }

            return isDisconnect;
        }
    }
}
